<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <button type="button" class="layui-btn layui-btn-primary" id="uploadExcel1">批量导入</button>
                    </form>


                </div>
                <div class="layui-card-body ">
                    <table class="layui-table" lay-data="{url:'/ranking/list',page:true,id:'rid'}" lay-filter="table">
                        <thead>
                        <tr>
                            <th lay-data="{type:'checkbox'}">ID</th>
                            <th lay-data="{field:'rid', width:100, sort: true}">RID</th>
                            <th lay-data="{field:'fname', width:100, sort: true, edit: 'text'}">首选科目</th>
                            <th lay-data="{field:'score', width:150,edit: 'text'}">分数段</th>
                            <th lay-data="{field:'same_num', edit: 'text', minWidth: 50}">同分数段人数</th>
                            <th lay-data="{field:'ranking', edit: 'text', minWidth: 50}">排名</th>
                            <th lay-data="{field:'year', edit: 'text', minWidth: 50}">年份</th>

                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    layui.use('table', function() {
        var table = layui.table;

        table.render({
            elem: '#start' //指定元素
        });

        table.render({
            elem: '#end' //指定元素
        });

        table.on('tool(table)',function (obj) {
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的DOM对象

            if (layEvent === 'del'){
                layer.confirm('确定删除这行么？', function(index){
                    obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                    layer.close(index);
                    //向服务端发送删除指令
                    $.ajax({
                        url: "/specialtygroup/del",
                        data: {"gid":data.gid},
                        method: "post",
                        success:function(d){
                            layer.alert(d, {
                                    icon: 6
                                },
                                function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        }
                    });
                });
            }else if(layEvent === 'edit'){
                layer.confirm('确定修改这行么？', function(index){
                    //向服务端发送删除指令
                    $.ajax({
                        url: "/specialtygroup/edit",
                        data: data,
                        method: "post",
                        success:function(d){
                            layer.alert(d, {
                                    icon: 6
                                },
                                function() {
                                    //关闭当前frame
                                    xadmin.close();
                                    // 可以对父窗口进行刷新
                                    xadmin.father_reload();
                                });
                        }
                    });
                });
            }
        });
    });
</script>
<script>layui.use('laydate',
    function() {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });

    });</script>

<script>
    layui.use('upload', function() {
        var upload = layui.upload;
        upload.render({
            elem: '#uploadExcel1'
            , url:'/ranking/fileUpload'//路径这看你怎么配置的怎么写
            , field:"file"
            , exts: 'xls|xlsx'
            , done: function (res) {
                if(res.success){
                    parent.layer.msg('导入成功！', {icon: 1,time:2000,shade:0.2});
                }
            }
        });
    });
</script>
</html>